/**
 * 系统版本更新
 */
import { store, updateToken } from '@s';
const statiConfig = window.__config__ || {};

const isNewVersion = () => {
	const version = statiConfig.VERSION;
	const { token } = store.getState().base;

	const localVersion = localStorage.getItem('version');
	// 存在版本
	if (version) {
		if (!localVersion) {
			store.dispatch(updateToken(token));
			localStorage.setItem('version', version);
			window.location.reload();
		} else {
			if (localVersion !== version) {
				Modal.confirm({
					title: '系统提示',
					content: '系统检测到有新版本，即将更新？',
					centered: true,
					onOk() {
						store.dispatch(updateToken(token));
						localStorage.setItem('version', version);
						window.location.reload();
					}
				});
			}
		}
	}
};

export default isNewVersion;
